home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / UPC12BS1.ZIP / MAIL / ADDRESS.C next >
C/C++ Source or Header  |  1993-06-21  |  28KB  |  694 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    a d d r e s s . c                                               */
  3. /*                                                                    */
  4. /*    Address parsing routines for UUPC/extended                      */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*    Changes Copyright (c) 1990-1993 by Kendra Electronic            */
  9. /*    Wonderworks.                                                    */
  10. /*                                                                    */
  11. /*    All rights reserved except those explicitly granted by the      */
  12. /*    UUPC/extended license agreement.                                */
  13. /*--------------------------------------------------------------------*/
  14.  
  15. /*--------------------------------------------------------------------*/
  16. /*                          RCS Information                           */
  17. /*--------------------------------------------------------------------*/
  18.  
  19. /*
  20.  *    $Id: address.c 1.7 1993/06/22 00:55:45 ahd Exp $
  21.  *
  22.  *    Revision history:
  23.  *    $Log: address.c $
  24.  * Revision 1.7  1993/06/22  00:55:45  ahd
  25.  * Trap routing entries when aliasing systems
  26.  *
  27.  * Revision 1.6  1993/06/21  04:04:04  ahd
  28.  * Don't fail routing loops from aliased systems with no route
  29.  *
  30.  * Revision 1.5  1993/06/21  02:17:31  ahd
  31.  * Correct errors in mail routing via HOSTPATH
  32.  *
  33.  */
  34.  
  35. /*--------------------------------------------------------------------*/
  36. /*                        System include files                        */
  37. /*--------------------------------------------------------------------*/
  38.  
  39. #include <ctype.h>
  40. #include <stdio.h>
  41. #include <string.h>
  42. #include <stdlib.h>
  43. #include <sys/types.h>
  44.  
  45. /*--------------------------------------------------------------------*/
  46. /*                    UUPC/extended include files                     */
  47. /*--------------------------------------------------------------------*/
  48.  
  49. #include "lib.h"
  50. #include "hlib.h"
  51. #include "address.h"
  52. #include "hostable.h"
  53. #include "security.h"
  54.  
  55. /*--------------------------------------------------------------------*/
  56. /*                          Global variables                          */
  57. /*--------------------------------------------------------------------*/
  58.  
  59. currentfile();
  60.  
  61. /*--------------------------------------------------------------------*/
  62. /*                     Local function prototypes                      */
  63. /*--------------------------------------------------------------------*/
  64.  
  65. static char *rfc_route( char *tptr, char **nptr, char **pptr );
  66.  
  67. /*--------------------------------------------------------------------*/
  68. /*    u s e r _ a t _ n o d e                                         */
  69. /*                                                                    */
  70. /*    break a UUCP path or RFC-822 address into the basic user and    */
  71. /*    node components                                                 */
  72. /*                                                                    */
  73. /*    Note:    This routine assume an address of the form             */
  74. /*             path!node1!user@node2 is for a user@node1 routed via   */
  75. /*             node2 and then path.                                   */
  76. /*--------------------------------------------------------------------*/
  77.  
  78. void user_at_node(const char *raddress,
  79.                   char *hispath,
  80.                   char *hisnode,
  81.                   char *hisuser)
  82. {
  83.  
  84.    static char *saveaddr = NULL;
  85.    static char *savepath;
  86.    static char *savenode;
  87.    static char *saveuser;
  88.  
  89.    char *uptr;                      /* Pointer to his user id              */
  90.    char *nptr;                      /* Pointer to his node id              */
  91.    char *pptr;                      /* Pointer to next node in path to him */
  92.    char *tptr;                      /* Temporary token pointer             */
  93.    char *wptr;                      /* Work pointer (not used between
  94.                                        steps                               */
  95.    char *address;
  96.  
  97.    struct HostTable *Hptr = NULL;   /* Pointer to host name table          */
  98.  
  99.  
  100.    if ( strlen( raddress ) >= MAXADDR )
  101.    {
  102.       printmsg(0,"Unable to process %d length address: %s",
  103.             strlen(raddress) , raddress );
  104.       panic();
  105.    }
  106.  
  107. /*--------------------------------------------------------------------*/
  108. /*                     Determine if local address                     */
  109. /*--------------------------------------------------------------------*/
  110.  
  111.    if (!strpbrk(raddress,"%!@"))    /* Any host delimiters?                */
  112.    {                                /* No --> report local data            */
  113.       strcpy(hisuser,raddress);
  114.       strcpy(hisnode,E_nodename);
  115.       strcpy(hispath,E_nodename);
  116.       strcpy(hisuser,raddress);
  117.       printmsg(5,"user_at_node: Address '%s' is local",raddress);
  118.       return;
  119.    }
  120.  
  121. /*--------------------------------------------------------------------*/
  122. /*    If the current address is the same as the last processed remote */
  123. /*    address, then return the same information as what we determined */
  124. /*    last time.                                                      */
  125. /*--------------------------------------------------------------------*/
  126.  
  127.    if ((saveaddr != NULL) && equal(raddress,saveaddr))
  128.    {
  129.       strcpy(hispath,savepath);
  130.       strcpy(hisnode,savenode);
  131.       strcpy(hisuser,saveuser);
  132.       return;
  133.    }
  134.  
  135. /*--------------------------------------------------------------------*/
  136. /*   The address is different; save the new address and then proceed  */
  137. /*   to parse it.                                                     */
  138. /*--------------------------------------------------------------------*/
  139.  
  140.    address = strdup(raddress);   /* Copy address for parsing         */
  141.    checkref(address);            /* Verify allocation worked         */
  142.  
  143.    if (saveaddr != NULL)         /* Was the data previously allocated?  */
  144.    {                             /* Yes --> Free it                     */
  145.       free(saveaddr);
  146.    }
  147.  
  148.    saveaddr = strdup(address);   /* Remember address for next pass   */
  149.  
  150. /*--------------------------------------------------------------------*/
  151. /*    If the address has no at sign (@), but does have a percent      */
  152. /*    sign (%), replace the last percent sign with an at sign.        */
  153. /*--------------------------------------------------------------------*/
  154.  
  155.    if ( strchr(address,'@') == NULL )  // Any at signs?
  156.    {                                // No --> Look further for %
  157.       wptr = strrchr(address,'%');  // Locate any percent signs
  158.  
  159.       if ( wptr != NULL )           // Got one?
  160.          *wptr = '@';               // Yup --> Make it an at sign at
  161.    }
  162.  
  163. /*--------------------------------------------------------------------*/
  164. /*                   Initialize routing information                   */
  165. /*--------------------------------------------------------------------*/
  166.  
  167.    nptr = nil(char);             /* No known node for user           */
  168.    pptr = E_mailserv;            /* Default routing via mail server  */
  169.    tptr = address;               /* Remember start of address        */
  170.  
  171. /*--------------------------------------------------------------------*/
  172. /*  The address may be RFC-822 syntax; attempt to parse that format   */
  173. /*--------------------------------------------------------------------*/
  174.  
  175.    uptr = tptr = rfc_route( tptr, &nptr, &pptr );
  176.  
  177. /*--------------------------------------------------------------------*/
  178. /*   If the user had an RFC-822 path, then the pointer to the path is */
  179. /*   now initialized, and the remainder of the path has been dropped  */
  180. /*   from *tptr; otherwise, the entire address is found via *tptr     */
  181. /*--------------------------------------------------------------------*/
  182.  
  183.    wptr  = strrchr(tptr,'@');  /* Get last at sign, since it's right
  184.                                   to left scan (more or